<?php
namespace Deployer;

require 'recipe/common.php';

set('application', 'my_project');
set('repository', 'https://gitee.com/subowen_admin/GinWebTest.git');
set('git_tty', true);
set('shared_files', []);
set('shared_dirs', []);
set('writable_dirs', []);
set('default_stage', 'local');


// Hosts
host('prod-adc01')
    ->user('chenshengwen')
    ->stage('prod')
    ->set('deploy_path', '/app/go1.10/src/github.com/huannet/GinWebTest');

localhost()
    ->stage('local')
    ->roles('test', 'build');
    

// Tasks

desc('Deploy your project');
task('deploy', [
    'deploy:info',
    'deploy:prepare',
    'deploy:lock',
    'deploy:release',
    'deploy:update_code',
    //'deploy:shared',
    //'deploy:writable',
    //'deploy:vendors',
    'deploy:clear_paths',
    'deploy:symlink',
    'deploy:unlock',
    'cleanup',
    'success'
]);

desc('Restart nginx service');
task('nginx:restart', function () {
    run('sudo systemctl restart nginx.service');
});

desc('Restart PHP-FPM service');
task('php-fpm:restart', function () {
    run('sudo systemctl restart php-fpm.service');
});

desc('Restart supervisord');
task('php-fpm:restart', function () {
    run('sudo systemctl restart supervisord.service');
});

desc('git push origin master');
task('git:push', function() {
    writeln('start git push task');
    $result = run('pwd');
    writeln("Current dir: $result");
    run('git add .');
    run('git commit -m "auto commit by deploy to gitee"');
    run('git push origin master');
});

// [Optional] If deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
